package com.jinyu.admin.config;

import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author: yangli
 * @Despriction:
 * @Package: com.jinyu.common.config
 * @Date:Created in 2022/5/4 15:27
 * @Modify By:
 */
@Slf4j
@Configuration
public class SaTokenConfigure implements WebMvcConfigurer {

    /**
     * 注册拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册Sa-Token的路由拦截器
        registry.addInterceptor(new SaInterceptor(handler -> {
                    // 根据路由划分模块，不同模块不同鉴权
                    // 登录认证 -- 拦截所有路由， 用于开放登录
                    SaRouter.match("/**",  r -> StpUtil.checkLogin());
                }))
                .addPathPatterns("/**")
                .excludePathPatterns("/base/refreshToken","/base/doLogin") //真实的登录地址
               ;
    }

}
